package com.ss.android.lockscreen.views.rounded;

import android.content.res.ColorStateList;
import android.graphics.Bitmap;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Matrix.ScaleToFit;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.support.annotation.NonNull;
import android.util.Log;
import android.widget.ImageView;

public final class a extends Drawable {
    final Paint a;
    Shader.TileMode b;
    Shader.TileMode c;
    boolean d;
    float e;
    final boolean[] f;
    boolean g;
    float h;
    ColorStateList i;
    ImageView.ScaleType j;
    private final RectF k;
    private final RectF l;
    private final RectF m;
    private final Bitmap n;
    private final Paint o;
    private final int p;
    private final int q;
    private final RectF r;
    private final Matrix s;
    private final RectF t;

    private a(Bitmap arg7) {

        this.k = new RectF();
        this.l = new RectF();
        this.m = new RectF();
        this.r = new RectF();
        this.s = new Matrix();
        this.t = new RectF();
        this.b = Shader.TileMode.CLAMP;
        this.c = Shader.TileMode.CLAMP;
        this.d = true;
        this.e = 0f;
        this.f = new boolean[]{true, true, true, true};
        this.g = false;
        this.h = 0f;
        this.i = ColorStateList.valueOf(-16777216);
        this.j = ImageView.ScaleType.FIT_CENTER;
        this.n = arg7;
        this.p = arg7.getWidth();
        this.q = arg7.getHeight();
        this.m.set(0f, 0f, ((float)this.p), ((float)this.q));
        this.o = new Paint();
        this.o.setStyle(Paint.Style.FILL);
        this.o.setAntiAlias(true);
        this.a = new Paint();
        this.a.setStyle(Paint.Style.STROKE);
        this.a.setAntiAlias(true);
        this.a.setColor(this.i.getColorForState(this.getState(), -16777216));
        this.a.setStrokeWidth(this.h);
    }

    public static Drawable a(Drawable arg4) {
        if(arg4 != null && !(arg4 instanceof a)) {
            if((arg4 instanceof LayerDrawable)) {
                int v1 = ((LayerDrawable)arg4).getNumberOfLayers();
                int v0;
                for(v0 = 0; v0 < v1; ++v0) {
                    ((LayerDrawable)arg4).setDrawableByLayerId(((LayerDrawable)arg4).getId(v0), a(((LayerDrawable)arg4).getDrawable(v0)));
                }
            } else {
                Bitmap v0_1 = b(arg4);
                if(v0_1 != null) {
                    arg4 = new a(v0_1);
                }
            }
        }

        return arg4;
    }

    final void a() {
        float v1;
        float v2;
        float v0 = 0f;
        float v5 = 0.5f;
        float v4 = 2f;
        switch(com.ss.android.lockscreen.views.rounded.b.a[this.j.ordinal()]) {
            case 1: {
                this.r.set(this.k);
                this.r.inset(this.h / v4, this.h / v4);
                this.s.reset();
                this.s.setTranslate(((float)(((int)((this.r.width() - (((float)this.p))) * v5 + v5)))), ((float)(((int)((this.r.height() - (((float)this.q))) * v5 + v5)))));
                break;
            }
            case 2: {
                this.r.set(this.k);
                this.r.inset(this.h / v4, this.h / v4);
                this.s.reset();
                if((((float)this.p)) * this.r.height() > this.r.width() * (((float)this.q))) {
                    v2 = this.r.height() / (((float)this.q));
                    v1 = (this.r.width() - (((float)this.p)) * v2) * v5;
                }
                else {
                    v2 = this.r.width() / (((float)this.p));
                    v1 = 0f;
                    v0 = (this.r.height() - (((float)this.q)) * v2) * v5;
                }

                this.s.setScale(v2, v2);
                this.s.postTranslate((((float)(((int)(v1 + v5))))) + this.h / v4, (((float)(((int)(v0 + v5))))) + this.h / v4);
                break;
            }
            case 3: {
                this.s.reset();
                v0 = (((float)this.p)) > this.k.width() || (((float)this.q)) > this.k.height() ? Math.min(this.k.width() / (((float)this.p)), this.k.height() / (((float)this.q))) : 1f;
                v1 = ((float)(((int)((this.k.width() - (((float)this.p)) * v0) * v5 + v5))));
                v2 = ((float)(((int)((this.k.height() - (((float)this.q)) * v0) * v5 + v5))));
                this.s.setScale(v0, v0);
                this.s.postTranslate(v1, v2);
                this.r.set(this.m);
                this.s.mapRect(this.r);
                this.r.inset(this.h / v4, this.h / v4);
                this.s.setRectToRect(this.m, this.r, Matrix.ScaleToFit.FILL);
                break;
            }
            case 5: {
                this.r.set(this.m);
                this.s.setRectToRect(this.m, this.k, Matrix.ScaleToFit.END);
                this.s.mapRect(this.r);
                this.r.inset(this.h / v4, this.h / v4);
                this.s.setRectToRect(this.m, this.r, Matrix.ScaleToFit.FILL);
                break;
            }
            case 6: {
                this.r.set(this.m);
                this.s.setRectToRect(this.m, this.k, Matrix.ScaleToFit.START);
                this.s.mapRect(this.r);
                this.r.inset(this.h / v4, this.h / v4);
                this.s.setRectToRect(this.m, this.r, Matrix.ScaleToFit.FILL);
                break;
            }
            case 7: {
                this.r.set(this.k);
                this.r.inset(this.h / v4, this.h / v4);
                this.s.reset();
                this.s.setRectToRect(this.m, this.r, Matrix.ScaleToFit.FILL);
                break;
            }
            default: {
                this.r.set(this.m);
                this.s.setRectToRect(this.m, this.k, Matrix.ScaleToFit.CENTER);
                this.s.mapRect(this.r);
                this.r.inset(this.h / v4, this.h / v4);
                this.s.setRectToRect(this.m, this.r, Matrix.ScaleToFit.FILL);
                break;
            }
        }

        this.l.set(this.r);
        this.d = true;
    }

    public static a a(Bitmap arg1) {
        a v0 = arg1 != null ? new a(arg1) : null;
        return v0;
    }

    private void a(Canvas arg9) {
        if(!b(this.f) && this.e != 0f) {
            float v0 = this.l.left;
            float v1 = this.l.top;
            float v2 = this.l.width() + v0;
            float v3 = this.l.height() + v1;
            float v4 = this.e;
            if(!this.f[0]) {
                this.t.set(v0, v1, v0 + v4, v1 + v4);
                arg9.drawRect(this.t, this.o);
            }

            if(!this.f[1]) {
                this.t.set(v2 - v4, v1, v2, v4);
                arg9.drawRect(this.t, this.o);
            }

            if(!this.f[2]) {
                this.t.set(v2 - v4, v3 - v4, v2, v3);
                arg9.drawRect(this.t, this.o);
            }

            if(this.f[3]) {
                return;
            }

            this.t.set(v0, v3 - v4, v4 + v0, v3);
            arg9.drawRect(this.t, this.o);
        }
    }

    private static boolean a(boolean[] arg4) {
        boolean v0 = false;
        int v2 = arg4.length;
        int v1 = 0;
        while(v1 < v2) {
            if(arg4[v1]) {
                v0 = true;
            }
            else {
                ++v1;
                continue;
            }

            return v0;
        }

        return v0;
    }

    private static Bitmap b(Drawable arg6) {
        Bitmap v0;
        int v2 = 2;
        if((arg6 instanceof BitmapDrawable)) {
            v0 = ((BitmapDrawable)arg6).getBitmap();
            return v0;
        }

        int v0_1 = Math.max(arg6.getIntrinsicWidth(), v2);
        int v1 = Math.max(arg6.getIntrinsicHeight(), v2);
        try {
            v0 = Bitmap.createBitmap(v0_1, v1, Bitmap.Config.ARGB_8888);
            Canvas v1_1 = new Canvas(v0);
            arg6.setBounds(0, 0, v1_1.getWidth(), v1_1.getHeight());
            arg6.draw(v1_1);
        }
        catch(Exception v0_2) {
            v0_2.printStackTrace();
            Log.w("RoundedDrawable", "Failed to create bitmap from drawable!");
            v0 = null;
        }

        return v0;
    }

    private static boolean b(boolean[] arg4) {
        boolean v0 = false;
        int v2 = arg4.length;
        int v1 = 0;
        while(true) {
            if(v1 >= v2) {
                return true;
            }
            else if(!arg4[v1]) {
                ++v1;
                continue;
            }

            return v0;
        }
    }

    public final void draw(@NonNull Canvas arg15) {
        if(this.d) {
            BitmapShader v0 = new BitmapShader(this.n, this.b, this.c);
            if(this.b == Shader.TileMode.CLAMP && this.c == Shader.TileMode.CLAMP) {
                v0.setLocalMatrix(this.s);
            }

            this.o.setShader(((Shader)v0));
            this.d = false;
        }

        if(this.g) {
            if(this.h > 0f) {
                arg15.drawOval(this.l, this.o);
                arg15.drawOval(this.r, this.a);
            }
            else {
                arg15.drawOval(this.l, this.o);
            }
        }
        else if(a(this.f)) {
            float v0_1 = this.e;
            if(this.h > 0f) {
                arg15.drawRoundRect(this.l, v0_1, v0_1, this.o);
                arg15.drawRoundRect(this.r, v0_1, v0_1, this.a);
                this.a(arg15);
                if(!b(this.f) && this.e != 0f) {
                    float v9 = this.l.left;
                    float v2 = this.l.top;
                    float v10 = v9 + this.l.width();
                    float v11 = v2 + this.l.height();
                    float v12 = this.e;
                    float v13 = this.h / 2f;
                    if(!this.f[0]) {
                        arg15.drawLine(v9 - v13, v2, v9 + v12, v2, this.a);
                        arg15.drawLine(v9, v2 - v13, v9, v2 + v12, this.a);
                    }

                    if(!this.f[1]) {
                        arg15.drawLine(v10 - v12 - v13, v2, v10, v2, this.a);
                        arg15.drawLine(v10, v2 - v13, v10, v2 + v12, this.a);
                    }

                    if(!this.f[2]) {
                        arg15.drawLine(v10 - v12 - v13, v11, v10 + v13, v11, this.a);
                        arg15.drawLine(v10, v11 - v12, v10, v11, this.a);
                    }

                    if(this.f[3]) {
                        return;
                    }

                    arg15.drawLine(v9 - v13, v11, v9 + v12, v11, this.a);
                    arg15.drawLine(v9, v11 - v12, v9, v11, this.a);
                }
            }
            else {
                arg15.drawRoundRect(this.l, v0_1, v0_1, this.o);
                this.a(arg15);
            }
        }
        else {
            arg15.drawRect(this.l, this.o);
            if(this.h <= 0f) {
                return;
            }

            arg15.drawRect(this.r, this.a);
        }
    }

    public final int getAlpha() {
        return this.o.getAlpha();
    }

    public final ColorFilter getColorFilter() {
        return this.o.getColorFilter();
    }

    public final int getIntrinsicHeight() {
        return this.q;
    }

    public final int getIntrinsicWidth() {
        return this.p;
    }

    public final int getOpacity() {
        return -3;
    }

    public final boolean isStateful() {
        return this.i.isStateful();
    }

    protected final void onBoundsChange(@NonNull Rect arg2) {
        super.onBoundsChange(arg2);
        this.k.set(arg2);
        this.a();
    }

    protected final boolean onStateChange(int[] arg3) {
        boolean v0_1;
        int v0 = this.i.getColorForState(arg3, 0);
        if(this.a.getColor() != v0) {
            this.a.setColor(v0);
            v0_1 = true;
        }
        else {
            v0_1 = super.onStateChange(arg3);
        }

        return v0_1;
    }

    public final void setAlpha(int arg2) {
        this.o.setAlpha(arg2);
        this.invalidateSelf();
    }

    public final void setColorFilter(ColorFilter arg2) {
        this.o.setColorFilter(arg2);
        this.invalidateSelf();
    }

    public final void setDither(boolean arg2) {
        this.o.setDither(arg2);
        this.invalidateSelf();
    }

    public final void setFilterBitmap(boolean arg2) {
        this.o.setFilterBitmap(arg2);
        this.invalidateSelf();
    }
}

